/**
/**
 * JAVACC DEMO 1.0
 */

package com.apache.excp.core.impl.exp;

import org.apache.log4j.Logger;

import com.apache.excp.ConfigConstant;
import com.apache.excp.core.impl.helper.ReportEnginer;
import com.apache.excp.core.manager.ExportExecl;
import com.apache.excp.core.model.ExportVo;

/**
 * description:  实现按模板导出数据到execl
 * @author Hou Dayu 创建时间：2014-7-28  
 */
public class ExportExeclImpl implements ExportExecl {

	private Logger log = Logger.getLogger(ExportExeclImpl.class);
	private ReportEnginer enginer;
	private String tempFile;

	/**
	 * TODO 实现按模板导出数据到execl.  
	 * @see com.zbxsoft.execl.manager.ExportExecl#exportData(com.zbxsoft.execl.model.ExportVo)  
	 */
	public Object exportData(ExportVo vo) {
		String path = vo.getFilePath();
		if (ConfigConstant.isNull(path)) {
			path = ConfigConstant.getClassLoaderPath().replace("WEB-INF/classes/", "downloadFile/");
		}
		ConfigConstant.newCreateFolder(path);
		try {
			//String tempFile = ConfigConstant.getClassLoaderPath() + "templates/";
			String newFile = path + vo.getNewFileName();
			getEnginer().excute(tempFile + vo.getTemplateName(), vo.getParams(), newFile);
		} catch (Exception e) {
			log.error(e);
		}
		return null;
	}

	private ReportEnginer getEnginer() {
		if (null == enginer) {
			enginer = new ReportEnginer();
		}
		if (ConfigConstant.isNull(tempFile)) {
			tempFile = ConfigConstant.getClassLoaderPath() + "templates/";
		}
		return enginer;
	}

}
